{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "from collections import defaultdict\n",
    "from datetime import datetime\n",
    "\n",
    "import requests\n",
    "from IPython.display import HTML\n",
    "\n",
    "r = requests.get('https://api.github.com/repos/django/django/stats/commit_activity')\n",
    "series = defaultdict(int)\n",
    "monthname = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',\n",
    "             'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\n",
    "\n",
    "for d in r.json():\n",
    "    month = datetime.fromtimestamp(d['week']).month\n",
    "    series[month] += d['total']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"chart\" style=\"width: 600px; height:400px;\"></div>\n",
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            echarts: '//cdn.bootcss.com/echarts/3.0.0/echarts.min',\n",
       "        }\n",
       "    });\n",
       "    require(['echarts'], function(ec) {\n",
       "        var myChart = ec.init(document.getElementById('chart'));\n",
       "        var option = {\n",
       "                title: {\n",
       "                    text: 'Last Year of commit activity',\n",
       "                    left: 'center'\n",
       "                },\n",
       "                subtitle: {\n",
       "                    text: 'https://github.com/django/django',\n",
       "                },\n",
       "                xAxis: {\n",
       "                    data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\n",
       "                },\n",
       "                yAxis: {},\n",
       "                series: [{\n",
       "                    name: 'Commits',\n",
       "                    type: 'line',\n",
       "                    data: [174, 134, 120, 130, 176, 141, 140, 211, 173, 144, 212, 122]\n",
       "                }]\n",
       "            };\n",
       "\n",
       "        myChart.setOption(option);\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HTML('''\n",
    "<div id=\"chart\" style=\"width: 600px; height:400px;\"></div>\n",
    "\n",
    "<script>\n",
    "    require.config({\n",
    "        paths: {\n",
    "            echarts: '//cdn.bootcss.com/echarts/3.0.0/echarts.min',\n",
    "        }\n",
    "    });\n",
    "    require(['echarts'], function(ec) {\n",
    "        var myChart = ec.init(document.getElementById('chart'));\n",
    "        var option = {\n",
    "                title: {\n",
    "                    text: 'Last Year of commit activity',\n",
    "                    left: 'center'\n",
    "                },\n",
    "                subtitle: {\n",
    "                    text: 'https://github.com/django/django',\n",
    "                },\n",
    "                xAxis: {\n",
    "                    data: %s\n",
    "                },\n",
    "                yAxis: {},\n",
    "                series: [{\n",
    "                    name: 'Commits',\n",
    "                    type: 'line',\n",
    "                    data: %s\n",
    "                }]\n",
    "            };\n",
    "\n",
    "        myChart.setOption(option);\n",
    "    });\n",
    "</script>\n",
    "''' % (monthname, series.values()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  },
  "widgets": {
   "state": {},
   "version": "1.1.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
